home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig18_04.jar / Ch18 / Fig18_04 / Fig18_04.cpp
C/C++ Source or Header  |  1997-11-10  |  723b  |  34 lines

  1. // Fig. 18.4: fig18_04.cpp
  2. // Using the exit and atexit functions 
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5.  
  6. void print( void );
  7.  
  8. int main()
  9. {
  10.    atexit( print );       // register function print 
  11.    cout << "Enter 1 to terminate program with function exit" 
  12.         << "\nEnter 2 to terminate program normally\n";
  13.  
  14.    int answer;
  15.    cin >> answer;
  16.  
  17.    if ( answer == 1 ) {
  18.       cout << "\nTerminating program with function exit\n";
  19.       exit( EXIT_SUCCESS );
  20.    }
  21.  
  22.    cout << "\nTerminating program by reaching the of main"
  23.         << endl;
  24.  
  25.    return 0;
  26. }
  27.  
  28. void print( void )
  29. {
  30.    cout << "Executing function print at program termination\n"
  31.         << "Program terminated" << endl;
  32. }
  33.  
  34.